<template>
    <c-dialog v-model:show="dialogFlag" v-if="dialogFlag" :title="title" @confirm="submit" @close="close"
        :btnDisabled="type == 3" width="600px">
        <br/>
        <el-form ref="userForm" :rules="rules" :model="formData" label-width="100px">
            <el-form-item label="志愿者" prop="volunteerMemberId">
                <fliter-select  v-model="formData.volunteerMemberId"/>
                <!-- <el-input v-model="formData.volunteerMemberId" :disabled="type == 3" /> -->
            </el-form-item>
        </el-form>
    </c-dialog>
</template>
<script setup>
import { ref, onMounted } from 'vue';
import cDialog from '@/components/custom/cDialog.vue'
import { message } from '@/utils/element'
import {sendServiceAidOrder} from '@/api/service'
import fliterSelect from "@/components/custom/fliterSelect.vue"

import { useUserStore } from '@/pinia/modules/user'

const userStore = useUserStore()

const props = defineProps({
    show: {
        type: Boolean,
        default: false
    },
    title: String,
    editData: Object,
    type: Number // 操作类型：1为新增，2为编辑，3为查看
})
const emit = defineEmits(['update:show', 'success'])
const formData = ref({})
const showEditor = ref(false)
onMounted(() => {
    if (props.type == 2 || props.type == 3) {
        formData.value.id = props.editData.id
    }
    
})

const rules = ref({
    userId: [
        { required: true, message: '请输入用户id', trigger: 'blur' }
    ],
    userName: [
        { required: true, message: '请输入用户名', trigger: 'blur' }
    ],
})

const userForm = ref(null)
const eleUpload = ref(null)
const dialogFlag = ref(props.show)

const submit = async () => {
    
    userForm.value.validate(async valid => {
        if (valid) {
            formData.value.volunteerMemberId = parseInt(formData.value.volunteerMemberId)
            const res = await sendServiceAidOrder(formData.value)
 
            if(res.code == 0){
                message('派单成功',2)
                emit('success')
                close()
            }
        } else {
            message('请正确填写表单信息', 3)
        }
    })
 
}

const getSlData = arr =>{
    console.log("EEEE:",arr)
    formData.value.topCategoryId = arr[0].id  // 顶级栏目（一级）
    formData.value.categoryName = (arr[1] && arr[1].name)?arr[1].name:''
}

const close = () => {
    emit('update:show', false)
}
</script>
<style lang="scss" scoped>
.mytips {
    font-size: 12px;
    color: #999;
}

.myitembox {
    display: flex;
    width: 100%;

    .myipitem {
        flex: 1;
    }

    .icontips {
        display: flex;
        padding: 0 0 0 4px;
        align-items: center;
    }
}
</style>
<style lang="scss">
.userFormItem {
    &.el-form-item--default {
        margin-bottom: 0;
    }
}
</style>